﻿@{
    ViewData["Title"] = "Index";
    Layout = "~/Areas/Console/Views/Shared/_Layout.cshtml";
}
@section head{
    <script type="text/javascript">
        var renderTable;
        layui.config({
            base: '../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'table', 'form'], function () {
            var $ = layui.$
                , form = layui.form
                , admin = layui.admin
                , table = layui.table;

            renderTable = function () {
                table.render({
                    elem: '#table-datalist'
                    , url: '/Console/CRMWallet/GetListJson'
                    , id: 'tableReload'
                    , toolbar: false
                    , defaultToolbar: false
                    , limit: 20
                    , title: '数据表'
                    , where: {
                        crmId: $("#Id").val()
                    }
                    , cols: [[
                        { field: 'index', title: '序号', type: 'numbers', width: 60, templet: '#crmWalletIndex' }
                        , {
                            field: 'fullName', title: '姓名', templet: function (res) {
                                return res.fullName;
                            }
                        }
                        , {
                            field: 'CRMAccount', title: 'CRM账户', templet: function (res) {
                                return res.loginName;
                            }
                        }
                        , {
                            field: 'MT5Account', title: 'MT5账号', templet: function (res) {
                                if (res.tradingAccount) {
                                    return res.tradingAccount;
                                } else {
                                    return "";
                                }
                            }
                        }
                        , { field: 'currency', title: '币种' }
                        , { field: 'balance', title: '余额' }
                        , { field: 'totalDeposit', title: '总入金' }
                        , {
                            field: 'totalWithdrawal', title: '总出金', templet: function (res) {
                                if (Number(res.totalWithdrawal) > 0) {
                                    return "- " + res.totalWithdrawal;
                                } else {
                                    return res.totalWithdrawal;
                                }
                            }
                        }
                        , { field: 'operate', fixed: 'right', title: '操作', toolbar: '#table-datalist-bar' }
                    ]]
                    , page: { layout: ['prev', 'page', 'next', 'refresh'] }
                    , done: function (res) {
                        if (res.count == 0) {
                            $(".layui-table-main").html('<div class="layui-none">' + top.lang.noData + '</div>');
                        }
                        layer.closeAll('loading');
                        /**多语言初始化 */
                        top.SetListPageLanguage(layui);
                    }
                });
            };
            //加载表格
            renderTable();

            //监听行工具事件
            table.on('tool(table-datalist)', function (obj) {
                var data = obj.data;
                if (obj.event === 'balanceAdjustment') {
                    top.OpenPageByKey(layui, "CRMBalanceAdjustment", 2, '600px', '450px', '/Console/CRMWallet/BalanceAdjustment?idList=' + data.id);
                } else if (obj.event === 'capitalFlow') {
                    parent.layui.index.openTabsPage("/Console/CRMWalletTransactions/Index?walletId=" + data.id, top.lang.capitalFlow + '(' + data.fullName + ')');
                    //初始化导航选项卡（选中新建标签卡）
                    parent.layui.element.render('nav');
                }
            });

            form.on('submit(resetting)', function (data) {
                $('#nameOrAccount').val("");
                $('#MT5Account').val("");
            });

            form.on('submit(search)', function (data) {
                //执行重载
                table.reload('tableReload', {
                    page: { curr: 1, layout: ['prev', 'page', 'next', 'refresh'] }
                    , where: {
                        nameOrAccount: $("#nameOrAccount").val(),
                        MT5Account: $("#MT5Account").val()
                    }
                });
            });

            form.on('submit(refresh)', function (data) {
                //执行重载
                table.reload('tableReload', {
                    page: { curr: 1, layout: ['prev', 'page', 'next', 'refresh'] }
                    , where: {
                        nameOrAccount: $("#nameOrAccount").val(),
                        MT5Account: $("#MT5Account").val()
                    }
                });
            });
        });
    </script>
}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card" lay-filter="component-form-element">
                <div class="layui-card-body layui-form layui-form-pane" style="padding: 15px;">
                    <div id="divSearch" class="layui-col-space10 layui-form-item">
                        <div class="layui-col-md3">
                            <label class="layui-form-label" lay-event="nameOrAccount">邮箱</label>
                            <div class="layui-input-inline">
                                <input type="text" id="nameOrAccount" name="nameOrAccount" placeholder="nameOrAccount" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <label class="layui-form-label" lay-event="MT5Account">姓名</label>
                            <div class="layui-input-inline">
                                <input type="text" id="MT5Account" name="MT5Account" placeholder="MT5Account" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-input-block" style="width:300px;">
                                <button class="layui-btn" lay-event="search" lay-submit lay-filter="search">搜索</button>
                                <button class="layui-btn layui-btn-warm" lay-submit="" lay-filter="resetting" lay-event="resetting">重置</button>
                                <button class="layui-btn layui-btn-primary" lay-submit="" lay-filter="refresh" lay-event="refresh">刷新</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-card">
                <div class="layui-card-body">
                    <table class="layui-hide" id="table-datalist" lay-filter="table-datalist"></table>
                    <script type="text/html" id="crmWalletIndex">
                        {{d.LAY_TABLE_INDEX+1}}
                    </script>
                    <script type="text/html" id="table-datalist-bar">
                        <button class="layui-btn layui-btn-xs" lay-event="balanceAdjustment">余额调整</button>
                        <button class="layui-btn layui-btn-danger layui-btn-xs" lay-event="capitalFlow">资金流水</button>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>